﻿@model GolfLeague.EditModels.ScoringVariableEditModel

<script type="text/javascript">
    $(document).ready(function () {
        $('#dialog').dialog({
            autoOpen: false,
            model: true
        });
        $('input:button').button();
        $('input:submit').button();
        $('input:reset').button();
        $('div#buttonlist a').hover(
		    function () { $(this).addClass('ui-state-hover'); },
		    function () { $(this).removeClass('ui-state-hover'); }
	    );
    });

    $(function () {
        $(".DeleteButton").click(function (e) {
            e.preventDefault();
            var recordToDelete = $(this).attr("id");
            recordToDelete = recordToDelete.replace("delete-", "");

            $("#dialog").dialog("option", "buttons", {
                "Yes": function () {
                    $(this).dialog("close");
                    if (recordToDelete != '') {
                        $.post("/ScoringMethod/ScoringVariablesDelete", { "id": recordToDelete },
                        function (data) {
                            $('#row-' + recordToDelete).fadeOut('slow');
                        });
                    }
                },
                "No": function () {
                    $(this).dialog("close");
                    return false;
                }
            });
            $("#dialog").dialog("open");
        });
    });

    $(function () {
        $(".EditButton").click(function (e) {
            e.preventDefault();
            var recordToEdit = $(this).attr("id");
            recordToEdit = recordToEdit.replace("edit-", "");

            if (recordToEdit != '') {
                window.location = '/ScoringMethod/ScoringVariablesEdit/' + recordToEdit;
            }
        });
    });

    $(function () {
        $(".CancelEditButton").click(function (e) {
            e.preventDefault();
            window.location = '/ScoringMethod/ScoringVariables';
        });
    });

</script>

@{
    ViewBag.Title = "ScoringVariables";
}

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Add Variable</legend>

        @Html.HiddenFor(model => model.NewScoringVariable.ScoringVariableID)

        <div class="editor-label">
            @Html.LabelFor(model => model.NewScoringVariable.DisplayName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.NewScoringVariable.DisplayName)
            @Html.ValidationMessageFor(model => model.NewScoringVariable.DisplayName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.NewScoringVariable.Description)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.NewScoringVariable.Description)
            @Html.ValidationMessageFor(model => model.NewScoringVariable.Description)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.NewScoringVariable.ClassType)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.NewScoringVariable.ClassType, new SelectList(new List<string> { "Player", "Score", "Stroke", "Team" }))
            @Html.ValidationMessageFor(model => model.NewScoringVariable.ClassType)
        </div>

        <p>
        @if (Model.NewScoringVariable.ScoringVariableID < 1)
        {
            <input type="submit" value="Add" />
        }
        else
        {
            <input type="submit" value="Save" />
            <input type="reset" class="CancelEditButton" value="Cancel" />
        }
        </p>
        <div id="dialog" title="Confirm Delete">Are you sure you want to delete this variable?</div>
    </fieldset>
}

<fieldset>
    <legend>Scoring Variables</legend>
    <table>
        <tr>
            <th>Display Name</th>
            <th>Description</th>
            <th>Class Type</th>
            <th></th>
        </tr>
@foreach (var item in Model.ScoringVariables) {
        <tr id="row-@item.ScoringVariableID">
            <td>@item.DisplayName</td>
            <td>@item.Description</td>
            <td>@item.ClassType</td>
            <td>
                <div id="buttonlist">
                    <a href="#" title="Edit Variable" class="EditButton ui-state-default ui-corner-all ui-icon ui-icon-pencil" id="edit-@item.ScoringVariableID"></a>
                    <a href="#" title="Delete Variable" class="DeleteButton ui-state-default ui-corner-all ui-icon ui-icon-trash" id="delete-@item.ScoringVariableID"></a>
                </div>
            </td>
        </tr>
}
    </table>
</fieldset>
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
